00001 Vehicle::Vehicle():TraffEduObject(){
00002 this->setObjectType(VEHICLE);
00003 objectGroup->setName("Vehicle");
00004 int totalPAT=osgwind->sizeOfFrames();
00005 for(int i=0;i<totalPAT;++i){
00006 vehiclePAT *temp=new vehiclePAT [1] ;
00007 temp->frameID=osgwind->getFrames()[i]->getFrameId();
00008 temp->objectPAT=osg::ref_ptr<osg::PositionAttitudeTransform>(
00009 new osg::PositionAttitudeTransform(*objectPAT,osg::CopyOp::SHALLOW_COPY));
00010 temp->objectPAT->addChild(objectGeode.get());
00011 temp->objectPAT->addChild(objectGroup.get());
00012 temp->objectPAT->getChild(1)->setName("Vehicle");
00013 objectPATvector.push_back(temp);
00014 }
00015 setObjectId();
00016 setInAnimation(0);
00017 }
00018 Vehicle::Vehicle(string pathname,float scale):TraffEduObject(pathname,scale){
00019
00020 this->setObjectType(VEHICLE);
00021 objectGroup->setName("Vehicle");
00022 int totalPAT=osgwind->sizeOfFrames();
00023 for(int i=0;i<totalPAT;++i){
00024 vehiclePAT *temp=new vehiclePAT [1] ;
00025 temp->frameID=osgwind->getFrames()[i]->getFrameId();
00026 temp->objectPAT=osg::ref_ptr<osg::PositionAttitudeTransform>(
00027 new osg::PositionAttitudeTransform(*objectPAT,osg::CopyOp::SHALLOW_COPY));
00028
00029 temp->objectPAT->addChild(objectGeode.get());
00030 temp->objectPAT->addChild(objectGroup.get());
00031 temp->objectPAT->getChild(1)->setName("Vehicle");
00032 objectPATvector.push_back(temp);
00033 }
00034 setObjectId();
00035 setInAnimation(0);
00036 }
00037
00038 void Vehicle::draw(osg::ref_ptr<osg::Group> root,int animationFlag){
00039
00040 if(animationFlag==-1 && modelPath=="models/carModels/dodgemax/butun.osg") {objectGroup->addChild(returnNode(0).get());}
00041 else if(animationFlag==-1 && modelPath=="models/carModels/semimax/butun.osg"){objectGroup->addChild(returnNode(1).get());}
00042 else objectGroup->addChild(returnNode().get());
00043
00044 this->setScale(modelScale, modelScale, modelScale);
00045
00046 this->addTree(root,animationFlag);
00047 viewMode=1;
00048 isBeforeCreated=1;
00049
00050
00051 }
00052 void Vehicle::hidePath(osg::ref_ptr<osg::Group> root){
00053 path.hide(root);
00054 }
00055 void Vehicle::displayPath(osg::ref_ptr<osg::Group> root){
00056 path.display(root);
00057 }
00058
00059 void Vehicle::drawPath(osg::ref_ptr<osg::Group> root){
00060 path.draw(root);
00061 }
00062 void Vehicle::setPath(){
00063
00064 }
00065 Path* Vehicle::getPath(){
00066 return &path;
00067 }
00068 void Vehicle::deletePath(){
00069 path.deletePart();
00070 }
00071
00072 void Vehicle:: reload(osg::ref_ptr<osg::Group> root,int animationFlag){
00073
00074 int numOfChildren=objectGroup->getNumChildren();
00075 for(int i=0;i<numOfChildren;i++)
00076 objectGroup->removeChild(0,1);
00077 numOfChildren=objectPAT->getNumChildren();
00078 for(int i=0;i<numOfChildren;i++)
00079 objectPAT->removeChild(0,1);
00080 if(animationFlag==1){
00081 this->resetModelPath("Butun");
00082 }
00083 else{
00084 this->resetModelPath("Vehicle");
00085 }
00086
00087 objectGroup->insertChild(0,returnNode().get());
00088 objectPAT->insertChild(0,objectGroup.get());
00089 this->setScale(modelScale, modelScale, modelScale);
00090 if(animationFlag!=1){
00091 setWheels( root);
00092 }
00093 }
00094
00095
00096 void Vehicle::setWheels(osg::ref_ptr<osg::Group> root){
00097 for(int i=0;i<4;++i){
00098
00099 wheelObjects[i].setModelScale(modelScale);
00100 wheelObjects[i].setModelPath(modelPath);
00101 if(i==1 || i==3)
00102 wheelObjects[i].resetModelPath("sol_teker");
00103 else
00104 wheelObjects[i].resetModelPath("sag_teker");
00105 wheelObjects[i].draw(root);
00106 }
00107
00108 }
00109 void Vehicle::setPositionAll(float x,float y,float z){
00110 int totalPAT=osgwind->sizeOfFrames();
00111 for(int i=0;i<totalPAT;++i){
00112 this->objectPATvector[i]->objectPAT->setPosition(osg::Vec3d(x,y,z));
00113 }
00114 }